<?php
require_once("lib/db_connection.php");
$type = $_GET['type'];
$job_id = $_GET['job_id'];
$temp_job_id = $_SESSION['temp_job_id'];

if($type == 'add')
{
	$query = "SELECT SUM(total_hrs) as hours, MIN(last_odometer) as start_odo, MAX(arrival_odometer) as end_odo FROM rou_job_loc_tbl WHERE temp_job_id='".$temp_job_id."'";
}
if($type == 'edit')
{
	$query = "SELECT SUM(total_hrs) as hours, MIN(last_odometer) as start_odo, MAX(arrival_odometer) as end_odo FROM rou_job_loc_tbl WHERE job_id='".$job_id."'";
}

$result = mysql_query($query) or die("SELECT LOCATIONS ".mysql_error());
$row = mysql_fetch_array($result);
$km = $row[end_odo] - $row[start_odo];

$db_hrs = $row[hours];
$decimal = strstr($db_hrs, '.');
$mins = round($decimal * 60);
$hr = $db_hrs - $decimal;
if($hr<10)
$new_hr = '0'.$hr;
if($hr>=10)
$new_hr = $hr;
$comp_hrs = $new_hr.'h'.' '.$mins.'m';

echo "new Array('$comp_hrs','$row[start_odo]','$row[end_odo]','$km')";
?>